﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Xml.Serialization;

namespace Perceiveit.Xml.Tests.Serialized
{
    [Serializable()]
    [XmlRoot("root",Namespace="http://schemas.perceiveit.co.uk/xmlobject/sample.xsd")]
    public class Root
    {

        #region class vars

        private int _integer;
        private string _string;
        private bool? _nullableBool;
        private DbType _dbenum;
        private Guid _guid;
        private byte _byte;
        private char _char;
        private DateTime _datetime;
        private decimal _decimal;
        private double _double;
        private float _float;
        private Color _color;
        private long _long;
        private Point _pt;
        private sbyte _sbyte;
        private short _short;
        private TimeSpan _timespan;
        private uint _uint;
        private ulong _ulong;
        private Uri _uri;
        private ushort _ushort;
        private LocalString _name;
        private LocalString _desc;
        private SimpleChildList _simple;

        private string _icon;
        private int? _nonexist;
        private string _newstring;

        #endregion

        

        [XmlAttribute("integer")]
        public int IntegerValue
        {
            get { return _integer; }
            set { _integer = value; }
        }

        [XmlAttribute("string")]
        public string StringValue
        {
            get { return _string; }
            set { _string = value; }
        }

        [XmlAttribute("guid")]
        public Guid GuidValue
        {
            get { return _guid; }
            set { _guid = value; }
        }

        private Perceiveit.Xml.Converters.NullableXConverter<bool> _bconv = new Perceiveit.Xml.Converters.NullableXConverter<bool>(new Perceiveit.Xml.Converters.BoolXConverter());

        [XmlAttribute("bool")]
        public string xBoolValue
        {
            get { return _bconv.ToString(BoolValue); }
            set { this.BoolValue = _bconv.FromString(value); }
        }

        [XmlIgnore()]
        public bool? BoolValue
        {
            get { return _nullableBool; }
            set { _nullableBool = value; }
        }

        [XmlAttribute("db-enum")]
        public DbType DbTypeValue
        {
            get { return _dbenum; }
            set { _dbenum = value; }
        }

        [XmlAttribute("byte")]
        public byte ByteValue
        {
            get { return _byte; }
            set { _byte = value; }
        }

        private Perceiveit.Xml.Converters.CharXConverter _charconv = new Perceiveit.Xml.Converters.CharXConverter();

        [XmlAttribute("char")]
        public string xCharValue
        {
            get { return _charconv.ToString(this.CharValue); }
            set { this.CharValue = _charconv.FromString(value); }
        }

        [XmlIgnore()]
        public char CharValue
        {
            get { return _char; }
            set { _char = value; }
        }

        private Perceiveit.Xml.Converters.DateTimeXConverter _dtConv = new Perceiveit.Xml.Converters.DateTimeXConverter();

        [XmlAttribute("datetime")]
        public string xDateTime
        {
            get { return _dtConv.ToString(this.DateValue); }
            set { this.DateValue = _dtConv.FromString(value); }
        }

        [XmlIgnore()]
        public DateTime DateValue
        {
            get { return _datetime; }
            set { _datetime = value; }
        }

        [XmlAttribute("decimal")]
        public Decimal DecimalValue
        {
            get { return _decimal; }
            set { _decimal = value; }
        }

        [XmlAttribute("double")]
        public Double DoubleValue
        {
            get { return _double; }
            set { _double = value; }
        }

        [XmlAttribute("float")]
        public float FloatValue
        {
            get { return _float; }
            set { _float = value; }
        }

        private Perceiveit.Xml.Converters.HTMLColorXConverter _colconv = new Perceiveit.Xml.Converters.HTMLColorXConverter();

        [XmlAttribute("color")]
        public string xColor
        {
            get { return _colconv.ToString(this.ColorValue); }
            set { this.ColorValue = _colconv.FromString(value); }
        }

        [XmlIgnore()]
        public Color ColorValue
        {
            get { return _color; }
            set { _color = value; }
        }

        [XmlAttribute("long")]
        public long LongValue
        {
            get { return _long; }
            set { _long = value; }
        }

        private Perceiveit.Xml.Converters.PointXConverter _ptconv = new Perceiveit.Xml.Converters.PointXConverter();
        
        [XmlAttribute("point")]
        public string xPointValue
        {
            get { return _ptconv.ToString(this.Point); }
            set { this.Point = _ptconv.FromString(value); }
        }

        [XmlIgnore()]
        public Point Point
        {
            get { return _pt; }
            set { _pt = value; }
        }

        [XmlAttribute("sbyte")]
        public sbyte SByteValue
        {
            get { return _sbyte; }
            set { _sbyte = value; }
        }

        [XmlAttribute("short")]
        public short ShortValue
        {
            get { return _short; }
            set { _short = value; }
        }

        private Perceiveit.Xml.Converters.TimeSpanXConverter _tsconv = new Perceiveit.Xml.Converters.TimeSpanXConverter();

        [XmlAttribute("timespan")]
        public string xTimeSpanValue
        {
            get { return _tsconv.ToString(this.TimeSpanValue); }
            set { this.TimeSpanValue = _tsconv.FromString(value); }
        }

        [XmlIgnore()]
        public TimeSpan TimeSpanValue
        {
            get { return _timespan; }
            set { _timespan = value; }
        }

        [XmlAttribute("uint")]
        public uint UIntValue
        {
            get { return _uint; }
            set { _uint = value; }
        }

        [XmlAttribute("ulong")]
        public ulong ULongValue
        {
            get { return _ulong; }
            set { _ulong = value; }
        }

        private Perceiveit.Xml.Converters.UriXConverter _uriconv = new Perceiveit.Xml.Converters.UriXConverter();

        [XmlAttribute("uri")]
        public string xUriValue
        {
            get { return _uriconv.ToString(this.UriValue); }
            set { this.UriValue = _uriconv.FromString(value); }
        }

        [XmlIgnore()]
        public Uri UriValue
        {
            get { return _uri; }
            set { _uri = value; }
        }

        [XmlAttribute("ushort")]
        public ushort UShortValue
        {
            get { return _ushort; }
            set { _ushort = value; }
        }

        [XmlElement("icon")]
        public string Icon
        {
            get { return _icon; }
            set { _icon = value; }
        }

        [XmlElement("non-existant")]
        public int? NonExistant
        {
            get { return _nonexist; }
            set
            {
                _nonexist = value;
            }
        }

        [XmlAttribute("new-string")]
        public string NewString
        {
            get { return _newstring; }
            set
            {
                _newstring = value;
            }
        }


        [XmlElement("name")]
        public LocalString NameValue
        {
            get { return _name; }
            set { _name= value; }
        }

        [XmlElement("description")]
        public LocalString DescriptionValue
        {
            get { return _desc; }
            set { _desc= value; }
        }


        [XmlArray("simple-child")]
        [XmlArrayItem("simple",typeof(SimpleChild))]
        public SimpleChildList SimpleChildren
        {
            get { return _simple; }
            set { _simple = value; }
        }

        //
        //.ctor
        //



        public Root()
            : base()
        {
        }
    }
}
